package org.ns.learn.rpc.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.ns.learn.rpc.codec.RpcResponse;

public class RpcClientHandler extends ChannelInboundHandlerAdapter {

    private MessageManage messageManage;

    private RpcClient rpcClient;


    public RpcClientHandler(RpcClient rpcClient, MessageManage messageManage) {
        this.messageManage = messageManage;
        this.rpcClient = rpcClient;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        RpcResponse response = (RpcResponse)msg;
        messageManage.setRpcResponse(new RpcClientResponse(rpcClient, response));
    }
}
